<template>
	<div>
		<form>

			<el-row>
				<el-col :span="10">

					<el-input v-model="query.name" placeholder="请输入检验名称" clearable></el-input>
				</el-col>

				<el-col :span="4">

					<el-button type="primary" @click="list">查询</el-button>
					<el-button type="primary" @click="add">添加</el-button>

				</el-col>
			</el-row>
		</form>

		<el-table size="mini" :data="tableData" style="width: 100%">


			<el-table-column type="selection">
			</el-table-column>

			<el-table-column label="序号" type="index">
			</el-table-column>
			<el-table-column label="检查名称" prop="name">
			</el-table-column>
			<el-table-column label="价格" prop="fee">
			</el-table-column>
			
			<el-table-column label="操作" width="300">
				<template slot-scope="scope">
					<el-button size="mini" @click="edit(scope.row.id)">编辑</el-button>
					<el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>


		<el-pagination background layout="prev, pager, next" @current-change="currentChange" :current-page.sync="query.pageNo"
		 :page-size="query.pageSize" :total="total">
		</el-pagination>

		<el-dialog title="编辑检验项目" :visible.sync="showEdit" width="480px">

			<InspectItemEdit :showEdit.sync="showEdit" @update="list" :id="id" :key="showNum"></InspectItemEdit>

		</el-dialog>

	</div>
</template>

<script>
	import InspectItemEdit from '@/views/inspect_item/edit'
	export default {
		name: 'InspectItem',
		components: {
			InspectItemEdit
		},
		data() {
			return {
				showNum: 0,
				total: 0,
				id: null,
				showEdit: false,
				query: {
					pageSize: 10,
					pageNo: 1,
					name: ''
				},
				tableData: []
			}
		},
		methods: {
			list() {

				this.axios.get('/inspect_item?type=query', (data) => {
					this.tableData = data.list;
					this.pageSize = data.pageSize;
					this.total = data.totalCount;
				}, this.query);
			},
			add() {
				this.showNum++;

				this.id = null;
				this.showEdit = true;
			},
			edit(id) {
				this.id = id;

				this.showNum++;
				this.showEdit = true;
			},
			del(id) {


				this.$confirm('删除数据, 是否继续?', '提示', {
					type: 'warning'
				}).then(() => {
					this.axios.get('/inspect_item?type=del', (data) => {
						if (data) {
							this.$alert("删除成功", "提示", {
								type: 'success'
							});
							//刷新页面
							this.list();
						}
					}, {
						id: id
					});
				});

			},
			currentChange() {
				this.list();
			}

		},
		created() {

			this.list();
		}
	}
</script>

<style>
</style>
